#include "Camera.h"


Camera::Camera()
{
}


Camera::~Camera()
{
}

void Camera::SetCameraPos(float _posX, float _posY, float _posZ, 
						  float _viewX, float _viewY, float _viewZ, 
						  float _dirX, float _dirY, float _dirZ)
{
	m_pos = Vector3(_posX, _posY, _posZ);
	m_view = Vector3(_viewX, _viewY, _viewZ);
	m_dir = Vector3(_dirX, _dirY, _dirZ);
}
void Camera::MoveCamera(float _speed)
{
	Vector3 _vector = Vector3(m_pos.X - m_view.X, m_pos.Y - m_view.Y, m_pos.Z - m_view.Z);

	// goc giua Y va Z cua camera
	float angle =  90 - atan(sqrt(pow(_vector.X, 2) + pow(_vector.Z, 2)) / _vector.Y) * 180 / 3.14;

	// Neu goc nho hon 27 thi k cho di chuyen xuong (_speed duong)
	if(angle < 27 && _speed > 0)
	{
		return;
	}

	m_pos.X  = m_pos.X  + _vector.X * _speed;
	m_pos.Z  = m_pos.Z  + _vector.Z * _speed;

	if(angle >=90)
		m_pos.Z = m_view.Z;

}

void Camera::RotateView(float speed)
{
	Vector3 _vector = Vector3(m_view.X - m_pos.X, m_view.Y - m_pos.Y, m_view.Z - m_pos.Z);

	m_view.Z = (float)(m_pos.Z + sin(speed) * _vector.X + cos(speed) * _vector.Z);
	m_view.X = (float)(m_pos.X + cos(speed) * _vector.X - sin(speed) * _vector.Z);
}

void Camera::RotatePositionH(float speed)
{	
	Vector3 _vector = Vector3(m_pos.X - m_view.X, m_pos.Y - m_view.Y, m_pos.Z - m_view.Z);

	m_pos.Z = (float)(m_view.Z + sin(speed) * _vector.X + cos(speed) * _vector.Z);
	m_pos.X = (float)(m_view.X + cos(speed) * _vector.X - sin(speed) * _vector.Z);
}

void Camera::RotatePositionV(float speed)
{	
	Vector3 _vector = Vector3(m_pos.X - m_view.X, m_pos.Y - m_view.Y, m_pos.Z - m_view.Z);

	//m_pos.Z = (float)(m_view.Z + sin(speed) * _vector.X + cos(speed) * _vector.Z);
	//m_pos.X = (float)(m_view.X + cos(speed) * _vector.X - sin(speed) * _vector.Z);

	m_pos.Y = (float)(m_view.Y + sin(speed) * _vector.Z + cos(speed) * _vector.Y + sin(speed) * _vector.X);
	m_pos.Z = (float)(m_view.Z + cos(speed) * _vector.Z - sin(speed) * _vector.Y - sin(speed) * _vector.X);

}